#include "DesignEntity.h"
#include <string>
using namespace std;

DesignEntity::~DesignEntity() {} 
DesignEntity::DesignEntity(SyntacticType t){
	type = t;
}
SyntacticType DesignEntity::getType(){
	return type;
}

bool DesignEntity::equal(DesignEntity* otherDE) {
	SyntacticType currentType = this->getType();
	if (currentType==otherDE->getType()){
		if (currentType==CONSTANT) {
			Constant* thisDE = dynamic_cast<Constant*>(this);
			Constant* thatDE = dynamic_cast<Constant*>(otherDE);
			return (thisDE->getValue()==thatDE->getValue());
		} else if (currentType==VARIABLE) {
			Variable* thisDE = dynamic_cast<Variable*>(this);
			Variable* thatDE = dynamic_cast<Variable*>(otherDE);
			return (thisDE->getIndex()==thatDE->getIndex());
		} else if (currentType==PROCEDURE) {
			Procedure* thisDE = dynamic_cast<Procedure*>(this);
			Procedure* thatDE = dynamic_cast<Procedure*>(otherDE);
			return (thisDE->getIndex()==thatDE->getIndex());
		} else if (currentType==STMTLIST) {
			return true;
		} else if (currentType==ASSIGN) {
			return true;
		} else if (currentType==WHILE) {
			return true;
		} else if (currentType==IF) {
			return true;
		} else if (currentType==PLUS) {
			return true;
		} else if (currentType==MINUS) {
			return true;
		} else if (currentType==TIMES) {
			return true;
		} else if (currentType==CALL) {
			Call* thisDE = dynamic_cast<Call*>(this);
			Call* thatDE = dynamic_cast<Call*>(otherDE);
			return (thisDE->getProcIndex()==thatDE->getProcIndex());
		} else if (currentType==PROGRAM) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}


Constant::Constant(int value) : DesignEntity(CONSTANT){
	this->value = value;
}
int Constant::getValue(){
	return value;
}

Variable::Variable(int index) : DesignEntity(VARIABLE){
	this->index = index;
}
int Variable::getIndex(){
	return index;
}

Procedure::Procedure(int index) : DesignEntity(PROCEDURE){
	this->index = index;
}
int Procedure::getIndex(){
	return index;
}

StmtList::StmtList() : DesignEntity(STMTLIST){}
Assign::Assign() : DesignEntity(ASSIGN){}
While::While() : DesignEntity(WHILE){}
If::If() : DesignEntity(IF){}
Plus::Plus() : DesignEntity(PLUS){}
Minus::Minus() : DesignEntity(MINUS){}
Times::Times() : DesignEntity(TIMES){}

Call::Call(int procIndex) : DesignEntity(CALL){
	this->procIndex = procIndex;
}
int Call::getProcIndex(){
	return procIndex;
}

Program::Program() : DesignEntity(PROGRAM){}